#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UTable.Objects.Handlers.Gestures
{
    public interface GestureRecognizer
    {
        /// <summary>
        /// The number of fingers this gesture contains
        /// </summary>
        Range ContactNumberRange { get; }

        /// <summary>
        /// The priority of this gesture recognizer
        /// The recognizer with higher priority can be used earlier, 
        /// and prevent the less priority recognizers from using
        /// </summary>
        int Priority { get; }

        bool IsSupportedGesture(Type gesture);

        /// <summary>
        /// Raised when the recognizer should start recognizing gesture.
        /// That is when the fingers number on the control satisfies the ContactNumberRange constraints.
        /// </summary>
        /// <param name="info">The current gesture information</param>
        void StartRecognize(GestureInfo info);


        /// <summary>
        /// Try to detect the gesture with the given info. 
        /// This function will be called by the LocalGestureEngine when any fingers moved
        /// 
        /// Note that the ContinueRecognize flag in info can be set
        /// to notify the gesture engine to continue recognizing with 
        /// other recognizers
        /// </summary>
        void Recognizing(GestureInfo info);


        /// <summary>
        /// Raised when the recognizer should end recognizing gesture.
        /// That is when the fingers number on the control does not satisfy the ContactNumberRange constraints any more.
        /// </summary>
        /// <param name="info">The current gesture information</param>
        void EndRecognize(GestureInfo info);

        LocalGestureEngine GestureEngine { get; set; }

        event GestureDetectedEventHandler GestureDetected;
    }

    public delegate void GestureDetectedEventHandler(GestureRecognizer sender, GestureDetectedEventArgs args);

    public class GestureDetectedEventArgs
    {
        public GestureDetectedEventArgs(Gesture gesture, double reliability)
        {
            this.DetectedGesture = gesture;
            this.Reliability = reliability;
        }

        public Gesture DetectedGesture { get; protected set; }

        public double Reliability { get; protected set; }
    }

    public class Range
    {
        public Range(int lowerBound, int uppperBound)
        {
            LowerBound = lowerBound;
            UpperBound = uppperBound;
        }

        public int LowerBound { get; set; }

        public int UpperBound { get; set; }
    }
}
